package com.cloudbroker.bcs.common.http;

import org.apache.http.NameValuePair;
import org.apache.http.client.fluent.Form;
import org.springframework.util.MultiValueMap;

import java.util.List;
import java.util.Map;

/**
 * Created by lvjx on 2015/7/14.
 */
public class HttpUtils {

    public static Form getFormFromMap(Map<String,Object> map){
        Form from =  Form.form();
        for (String key : map.keySet()) {
            from.add(key,String.valueOf(map.get(key)));
        }
        return from;
    }

    public static List<NameValuePair> getBuildFormFromMap(Map<String,Object> map){
        return getFormFromMap(map).build();
    }


    public static List<NameValuePair> getBuildFormFromMultiMap(MultiValueMap<String,Object> map){
        Form from =  Form.form();
        for (String key : map.keySet()) {
            List list = map.get(key);
            for (Object o : list) {
                from.add(key,String.valueOf(o));
            }

        }
        return from.build();
    }
}
